package com.zj.study.config;

import com.zj.study.utils.validation.core.ConstraintValidationAspect;
import com.zj.study.utils.validation.core.ConstraintValidatorMapper;
import com.zj.study.utils.validation.core.LazyConstraintValidatorMapper;
import com.zj.study.utils.validation.validator.CommonValidator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @author 赵赳
 * @since 2021/9/24 9:13
 */
public class ValidationConfiguration {

  @Bean
  @ConditionalOnMissingBean
  public ConstraintValidatorMapper constraintValidatorMapper() {
    return new LazyConstraintValidatorMapper();
  }

  @Bean
  @ConditionalOnMissingBean
  public CommonValidator commonValidator() {
    return new CommonValidator();
  }

  @Bean
  @ConditionalOnMissingBean
  public ConstraintValidationAspect constraintValidationAspect(
      ApplicationContext applicationContext) {
    return new ConstraintValidationAspect(applicationContext);
  }
}
